package com.medicine.hbp.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.medicine.hbp.adapter.ClassificationDetailAdapter;
import com.medicine.hbp.base.BaseActivity;
import com.medicine.hbp.scrollview.MyScrollView;
import com.medicine.hbp.scrollview.MyScrollView.OnScrollListener;
import com.medicine.hbp.xListView.XListView;
import com.medicine.hbp.R;

/**
 * 个人用户界面
 *
 * @author jindandan
 */
public class SelfUserActivity extends BaseActivity implements OnScrollListener {
	private LinearLayout ll_btn_select;
	private MyScrollView myScrollView;
	private int searchLayoutTop;

	LinearLayout search01, search02;
	RelativeLayout rlayout;

	private XListView listView;
	private ClassificationDetailAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.self_users);
		// 初始化控件
		init();
	}

	private void init() {
		ll_btn_select = (LinearLayout) findViewById(R.id.ll_btn_select);
		myScrollView = (MyScrollView) findViewById(R.id.myScrollView);
		search01 = (LinearLayout) findViewById(R.id.search01);
		search02 = (LinearLayout) findViewById(R.id.search02);
		rlayout = (RelativeLayout) findViewById(R.id.rlayout);
		myScrollView.setOnScrollListener(this);

		listView=(XListView) findViewById(R.id.xListView_detail);
		adapter=new ClassificationDetailAdapter(aty);
		listView.setAdapter(adapter);
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < 10; i++) {
			list.add("1");
		}
		adapter.addItems(list);

	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		if (hasFocus) {
			searchLayoutTop = rlayout.getBottom();// 获取searchLayout的顶部位置
		}
	}

	// 监听滚动Y值变化，通过addView和removeView来实现悬停效果
	@Override
	public void onScroll(int scrollY) {
		if (scrollY >= searchLayoutTop) {
			if (ll_btn_select.getParent() != search01) {
				search02.removeView(ll_btn_select);
				search01.addView(ll_btn_select);
			}
		} else {
			if (ll_btn_select.getParent() != search02) {
				search01.removeView(ll_btn_select);
				search02.addView(ll_btn_select);
			}
		}
	}
}
